package com.m3958.firstgwt.server.service;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import com.google.inject.Singleton;
import com.m3958.firstgwt.server.utils.Osdetecter;
import com.m3958.firstgwt.server.utils.PropsUtils;

@Singleton
public class SiteConfigerPropertiesImpl implements SiteConfiger{
	
	private Properties props;
	
	private Map<String, String> propsHash = new HashMap<String, String>();
	
	public SiteConfigerPropertiesImpl() throws Exception{
		props = PropsUtils.load("siteconfig.properties");
		Enumeration en = props.propertyNames();
		boolean iswin = Osdetecter.isWindows();
		
		while (en.hasMoreElements()) {
			String key = (String) en.nextElement();
			String value = props.getProperty (key);
			String[] kk = key.split("\\s+");
			if(iswin){
				if(!"win".equals(kk[1]))continue;
			}else{
				if("win".equals(kk[1]))continue;
			}
			propsHash.put(kk[0], value);
		}
	}

	@Override
	public String getValue(String key) {
		return propsHash.get(key);
	}

}
